import org.springframework.web.context.request.RequestContextListener;

import javax.servlet.ServletRequestEvent;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by iss on 17/6/9.
 */
public class RCListener extends RequestContextListener {

    private  ThreadLocal<Map<String, Date>> threadLocal = new ThreadLocal<Map<String, Date>>();

    @Override
    public void requestInitialized(ServletRequestEvent requestEvent) {
        threadLocal.set(new HashMap<String, Date>());
        threadLocal.get().put("sTime", new Date());
        super.requestInitialized(requestEvent);
    }

    @Override
    public void requestDestroyed(ServletRequestEvent requestEvent) {
        Date sTime = threadLocal.get().get("sTime");
        if (null != sTime) {
            System.out.println(new Date().getTime() - sTime.getTime());
        }
        super.requestDestroyed(requestEvent);

    }
}
